﻿using System;
using COC.Character;
using COC.Character.Extra;
using UnityEngine;
using System.Collections;
using COC.Algorithm;
using Object = UnityEngine.Object;

namespace COC.Algorithm
{
public class ObjectPool : BaseBehaviourSupport {

    private static PoolManager<string, Component> objsPoolManager;

    public override void OnAwake()
    {
        if (objsPoolManager == null)
        {

            objsPoolManager = new PoolManager<string, Component>(this.gameObject);
        }
        objsPoolManager.SetDefaultGameobject += generateDefaultGameObject;

    }
    public static PoolManager<string, Component> getInstance()
    {
        return objsPoolManager;
    }

    public GameObject generateDefaultGameObject(string prefab)
    {
        if (prefab.Equals(Characters.MAP_TILE))
            return Resources.Load(Characters.Resource.Path.MAP_TILE,typeof(GameObject)) as GameObject;

        if (prefab.Equals(Characters.ARCHER))
            return Resources.Load(Characters.Resource.Path.ARCHER,typeof(GameObject)) as GameObject;
        return null;
    }

    public override void OnDestroy()
    {
        if (objsPoolManager != null)
        {

            objsPoolManager.SetDefaultGameobject += delegate { return null; };
            objsPoolManager = null;
        }
    }
}
    
}
